<!DOCTYPE html>
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Cache-Control"  content="no-transform">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>充值</title>
    <link href="/statics/view/css/yy_common.css" rel="stylesheet">
    <link href="/statics/view/css/yy_pay.css" rel="stylesheet">
<body>
<div class="m-pay-order m-pay-recharge">
    <div data-pro="list"></div>
    <div data-pro="options" class="m-pay-order-options">
        <div class="m-simpleHeader" id="pro-view-0">
            <a href="javascript:void(0);" data-pro="back" data-back="true"class="m-simpleHeader-back"><i class="ico ico-back"></i></a>
            <h1>充值</h1>
        </div>
        <div class="w-bar m-pay-noBgTitleBar" id="pro-view-1">1、选择充值金额（宝币）</div>
        <div class="m-pay-moneySelector" id="pro-view-2">
            <div class="m-pay-moneySelector-item m-pay-moneySelector-item-selected" id="pro-view-3" data-amount="20">20宝币</div>
            <div class="m-pay-moneySelector-item" id="pro-view-1" data-amount="50">50宝币</div>
            <div class="m-pay-moneySelector-item" id="pro-view-2" data-amount="100">100宝币</div>
            <div class="m-pay-moneySelector-item" id="pro-view-2" data-amount="200">200宝币</div>
            <div class="m-pay-moneySelector-item" id="pro-view-3"><input type="text" name="amount" placeholder="其他数额" pattern="[0-9]*"></div>
        </div>
        <div class="w-bar" id="pro-view-8">2、选择支付方式</div>
            <span class="pro-radioGroup" id="pro-view-9">
                <div class="w-radioBar w-bar w-radioBar-checked" id="pro-view-10">
                    <b class="w-radio"></b>
                    话费购
                <div class="w-bar-ext">
                    <input name="paymentPluginId" value="wo3DirectPlugin" type="radio">
                </div>
                </div>
            </span>
        </div>
    <div data-pro="submit" class="m-pay-order-submit"><button class="w-button w-button-main w-button-l" id="payBtn">提交</button></div>
</div>
<form id="doaiAppPayFrom"  action="" method="post"></form>
<script src="/statics/jquery/jquery.min.js"></script>
<script src="/statics/view/js/db.js"></script>
<script type="text/javascript">
    $(function(){
        $(".m-pay-moneySelector-item").click(function(){
            $(".m-pay-moneySelector-item").removeClass("m-pay-moneySelector-item-selected");
            $(this).addClass("m-pay-moneySelector-item-selected");
        });
        $("#payBtn").click(function(){
            var amount=$(".m-pay-moneySelector-item-selected").attr("data-amount");
            if(amount==null){
                var re = /^[0-9]+.?[0-9]*$/;
                amount=$("input[name='amount']").val();
                if (!re.test(amount))
                {
                    alert("请输入数字");
                    $("input[name='amount']").val("");
                }
            }
             paySubmit(amount);
        });
        $("input[name='amount']").change(function(){
            var re = /^[0-9]+.?[0-9]*$/;
            var number = $(this).val();
            if (!re.test(number))
            {
                alert("请输入数字");
                $(this).val("");
            }
        });
    });

    function paySubmit(amount){
        $.ajax({
            url: "/dMember/rechargeSubmit",
            type:'POST',
            data:{amount:amount,paymentPluginId:'wo3DirectPlugin'},
            dataType:'json',
            success: function (data){
               if(data.type=='success'){
                   $("#doaiAppPayFrom").attr("action",data.requestUrl);
                   $("#doaiAppPayFrom").attr("method",data.requestMethod);
                   for (var key in data.parameterMap) {
                       var str="<input type='hidden' name='"+key+"' value='"+data.parameterMap[key]+"'/>";
                       $(str).appendTo("#doaiAppPayFrom")
                   }
                   $("#doaiAppPayFrom").submit();
               }else{
                   alert(data.content);
               }
            }
        });
    }
</script>
</body>
</html>